<%@page import="com.itwill.ecom.product.ProductServiceImpl"%>
<%@page import="com.itwill.ecom.product.ProductBeans"%>
<%@page import="com.itwill.ecom.cart.CartService"%>
<%@page import="java.util.List"%>
<%@page import="com.itwill.ecom.cart.CartBeans"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@ page language="java" contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8"%>

<%
	System.out.println("△get_cartJSON요청△");

	WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(application);
	CartService cartService = (CartService)webApplicationContext.getBean("cartService");
	ProductServiceImpl productService = (ProductServiceImpl)webApplicationContext.getBean("productService");
	
	
//////////////////////////////////////////////////////////////////////////////////////
	String s_id=(String)session.getAttribute("sid");
	System.out.println("카트 리스트 받아오기~~~~~~:"+s_id);
	int s_noStr=Integer.parseInt(String.valueOf(session.getAttribute("sno")));
	System.out.println("카트 리스트 받아오기~~~~~~:"+s_noStr);
	//int s_no=Integer.parseInt(s_noStr.trim());
	// 정식
	//int memberNo = Integer.parseInt(request.getParameter("member_no"));
	//List<CartBeans> cartBeansList = cartService.getCartListByMemberNo(memberNo);
	
	// TEST ver
	List<CartBeans> cartBeansList = cartService.getCartListByMemberNo(s_noStr);
	
//////////////////////////////////////////////////////////////////////////////////////
%>

[
<%
	int count=0;
	for(int i=0;i<cartBeansList.size();i++){
		int product_no=cartBeansList.get(i).getCart_product();
		ProductBeans product=productService.getProductByNo(product_no);
		CartBeans cartBeans=cartBeansList.get(i);
%>
		{
			"cart_no" : "<%=cartBeans.getCart_no()%>",
			"cart_member" : "<%=cartBeans.getCart_member()%>",
			"cart_product" : "<%=cartBeans.getCart_product()%>",
			"cart_count" : "<%=cartBeans.getCart_count()%>",
			"product_no":"<%= product.getProduct_no()%>",
			"product_name":"<%= product.getProduct_name()%>",
			"product_price":"<%=product.getProduct_price()%>",
			"product_image":"<%= product.getProduct_image0()%>",
			"product_count":"<%= product.getProduct_no()%>"
		}
<%
		if((count+1) != cartBeansList.size()){
			out.print(",");
		}
		count++;
	}
%>
]
